package xiyuan.view.distance;

import java.util.List;

import xiyuan.exception.NoKeywordsException;
import xiyuan.keywords.tfidf.KeyWord;


public class NormalizedDistance {
	private final static double MAX_DIS = 4.0;
	public static double getDistance
		(String wordA, String wordB){
		if (TongYiCi.isSynonym(wordA, wordB)){
			return 0;
		}
		double dis = GoogleDistance.getDistance(wordA, wordB);
		if (dis < 0){
			dis = 0;
		}
		if (Double.isNaN(dis)){
			dis = MAX_DIS;
		}
		return dis;
	}
	public static double getDistanceByListAndTag(List<KeyWord> keywords,
			String checkTag) throws NoKeywordsException {
		double distance = 0;//这是结果distance变量
		if (keywords == null && keywords.size() == 0)
			throw new NoKeywordsException();
		for (KeyWord keyword: keywords){  
	    	String word = keyword.getWord();
	    	distance += NormalizedDistance.
	    		getDistance(checkTag, word) * keyword.getValue();
		}  
		return distance;
	}
}
